/**
 *
 */

package lohmar.ashar.android.batterySaver.helper;

import android.bluetooth.BluetoothAdapter;
import android.content.ContextWrapper;

/**
 * @author Mihai HARAS (Lohmar ASHAR) 2011
 */
public class BluetoothHelper implements IServiceHelper {

    private ContextWrapper context;

    public BluetoothHelper(ContextWrapper context) {
        this.context = context;
    }

    /*
     * (non-Javadoc)
     * @see lohmar.ashar.android.batterySaver.helper.IServiceHelper#isServiceEnabled()
     */
    @Override
    public boolean isServiceEnabled() {
        return BluetoothAdapter.getDefaultAdapter().isEnabled();
    }

    /*
     * (non-Javadoc)
     * @see lohmar.ashar.android.batterySaver.helper.IServiceHelper#isServicePresent()
     */
    @Override
    public boolean isServicePresent() {
        return BluetoothAdapter.getDefaultAdapter() != null;
    }

    /*
     * (non-Javadoc)
     * @see lohmar.ashar.android.batterySaver.helper.IServiceHelper#setServiceEnabled(boolean)
     */
    @Override
    public void setServiceEnabled(boolean serviceEnabled) {
        if (isServiceEnabled() != serviceEnabled) {
            BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (serviceEnabled) {
                bluetoothAdapter.enable();
            } else {
                bluetoothAdapter.disable();
            }
        }
    }

    @Override
    public String getServiceName() {
        return "bluetooth";
    }

}
